package com.example.video.admin_server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.video.admin_server.entity.SysUser;
import com.example.video.admin_server.entity.dto.SysUserDto;
import com.example.video.admin_server.entity.vo.SysUserDetailVo;
import com.example.video.admin_server.service.ISysUserService;
import com.example.video.common.util.ResponseWrap;
import com.example.video.common.util.ResponseWrapUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台管理员表 前端控制器
 * </p>
 *
 * @author yj
 */
@RestController
@RequestMapping("/admin/sys-user")
public class SysUserController {

    @Autowired
    private ISysUserService iSysUserService;

    @PostMapping("/add")
    @ApiOperation(value = "新增管理员")
    public ResponseWrap add(@RequestBody SysUserDto sysUserDto){
        boolean save = iSysUserService.add(sysUserDto);
        return ResponseWrapUtil.success();
    }

    @DeleteMapping ("/delUser")
    @ApiOperation(value = "删除角色")
    public ResponseWrap delRole(Integer id){
        boolean del = iSysUserService.delUser(id);
        return ResponseWrapUtil.success();
    }

    @PostMapping ("/update")
    @ApiOperation(value = "修改角色")
    public ResponseWrap update(@RequestBody SysUserDto sysUserDto){
        boolean update = iSysUserService.update(sysUserDto);
        return ResponseWrapUtil.success();
    }

    @GetMapping("/getDetails")
    @ApiOperation(value = "获取角色详情")
    public ResponseWrap<SysUserDetailVo> getDetails(Integer id){
        SysUserDetailVo sysRoleDetailsVo = iSysUserService.getDetails(id);
        return ResponseWrapUtil.success(sysRoleDetailsVo);
    }

    @GetMapping("/getPaginationList")
    @ApiOperation(value = "条件分页查询菜单列表")
    public ResponseWrap<Page<SysUser>> getPaginationList(Integer pageSize, Integer pageIndex, SysUser sysUser){
        Page<SysUser> page = iSysUserService.page(new Page<SysUser>(pageIndex, pageSize));
        return ResponseWrapUtil.success(page);
    }
}

